import types

string_encoding = 'latin1'

def st(s):
    return unicode(s, string_encoding)

status_dict = {
    1 : 'Ordered',
    2 : 'Available',
    3 : 'Unavailable',
    4 : 'Wanted',
    5 : 'Review'
}

media_dict = {
    1: 'Blu-ray',
    2: 'DVD',
    3: 'Other'
}

genre_dict = {
    1: 'Action',
    2: 'Comedy',
    3: 'Thriller',
    4: 'Horror',
    5: 'Music',
    6: 'Documentary',
    7: 'Animation',
    8: 'Romance',
    9: 'Drama',
    10: 'Sci-fi',
    11: 'Adult',
    12: 'Mystery',
    13: 'Adventure'
}

reverse_genre_dict = {}
for k,v in genre_dict.items():
    reverse_genre_dict[v] = k

class MovieStatus:
    Ordered = 1
    Available = 2
    Unavailable = 3
    Wanted = 4
    Review = 5

class MediaType:
    Bluray = 1
    DVD = 2
    Other = 3

def smart_str(s, encoding='utf-8', strings_only=False, errors='strict'):
    """
    Returns a bytestring version of 's', encoded as specified in 'encoding'.
    If strings_only is True, don't convert (some) non-string-like objects.
    """
    if strings_only and isinstance(s, (types.NoneType, int)):
        return s
    if isinstance(s, str):
        return unicode(s).encode(encoding, errors)
    elif not isinstance(s, basestring):
        try:
            return str(s)
        except UnicodeEncodeError:
            if isinstance(s, Exception):
                # An Exception subclass containing non-ASCII data that doesn't
                # know how to print itself properly. We shouldn't raise a
                # further exception.
                return ' '.join([smart_str(arg, encoding, strings_only,
                        errors) for arg in s])
            return unicode(s).encode(encoding, errors)
    elif isinstance(s, unicode):
        return s.encode(encoding, errors)
    elif s and encoding != 'utf-8':
        return s.decode('utf-8', errors).encode(encoding, errors)
    else:
        return s

#try:
#    unicode(s, 'ISO-8859-1'))
#except (UnicodeEncodeError, UnicodeDecodeError), e:
#    pass
#s.encode('utf-8')
    